package com.ruoyi.finance.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.finance.domain.BuyPayReq;
import com.ruoyi.finance.service.IBuyPayReqService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购付款申请Controller
 * 
 * @author lvql
 * @date 2024-11-07
 */
@RestController
@RequestMapping("/buyPayReq")
public class BuyPayReqController extends BaseController
{
    @Autowired
    private IBuyPayReqService buyPayReqService;

    /**
     * 查询采购付款申请列表
     */
    @RequiresPermissions("finance:buyPayReq:list")
    @GetMapping("/list")
    public TableDataInfo list(BuyPayReq buyPayReq)
    {
        startPage();
        List<BuyPayReq> list = buyPayReqService.selectBuyPayReqList(buyPayReq);
        return getDataTable(list);
    }

    /**
     * 导出采购付款申请列表
     */
    @RequiresPermissions("finance:buyPayReq:export")
    @Log(title = "采购付款申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyPayReq buyPayReq)
    {
        List<BuyPayReq> list = buyPayReqService.selectBuyPayReqList(buyPayReq);
        ExcelUtil<BuyPayReq> util = new ExcelUtil<BuyPayReq>(BuyPayReq.class);
        util.exportExcel(response, list, "采购付款申请数据");
    }

    /**
     * 获取采购付款申请详细信息
     */
    @RequiresPermissions("finance:buyPayReq:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(buyPayReqService.selectBuyPayReqById(id));
    }

    /**
     * 新增采购付款申请
     */
    @RequiresPermissions("finance:buyPayReq:add")
    @Log(title = "采购付款申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyPayReq buyPayReq)
    {
        logger.info("BuyPayReqController add params {}", buyPayReq);
        return toAjax(buyPayReqService.insertBuyPayReq(buyPayReq));
    }


    /**
     * 修改采购付款申请
     */
    @RequiresPermissions("finance:buyPayReq:edit")
    @Log(title = "采购付款申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyPayReq buyPayReq)
    {
        return toAjax(buyPayReqService.updateBuyPayReq(buyPayReq));
    }

    @RequiresPermissions("finance:buyPayReq:edit")
    @Log(title = "采购付款审核", businessType = BusinessType.UPDATE)
    @PostMapping("/approval")
    public AjaxResult approval(@RequestBody BuyPayReq buyPayReq)
    {
        return toAjax(buyPayReqService.approvalBuyPayReq(buyPayReq));
    }


    /**
     * 删除采购付款申请
     */
    @RequiresPermissions("finance:buyPayReq:remove")
    @Log(title = "采购付款申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        if (ids == null || ids.length == 0) {
            return AjaxResult.error("参数错误");
        }
        return toAjax(buyPayReqService.deleteBuyPayReqByIds(ids));
    }
}
